import GameMgr from "./gameMgr";
import musicMgr from "./musicMgr";

const { ccclass, property } = cc._decorator;

@ccclass
export default class gameStart extends cc.Component {

    _gamePrefabs: cc.Prefab[] = []

    _layout: cc.Node = null

    @property
    cardWidth: number = 90
    @property
    cardHeight: number = 110

    onLoad() {
        GameMgr.instance.cardWidth = this.cardWidth
        GameMgr.instance.cardHeight = this.cardHeight
        // 播放动画
    }

    startGame() {
        // 播放音乐
        GameMgr.instance.musicMgr = new musicMgr()
        GameMgr.instance.musicMgr.init()
        GameMgr.instance.musicMgr.playBgm("bgm")

        // 加载游戏布局场景
        cc.director.loadScene("game_scence", (err, scence: cc.Scene) => {
            if (!err) {
                // 获取Layout的宽高等信息
                let Canvas = scence.getChildByName("Canvas")
                let bgc = Canvas.getChildByName("bgc")
                let layout = bgc.getChildByName("layout")
                this._layout = layout
                GameMgr.instance._layout = layout

                // 加载预制卡片模版
                cc.loader.loadResDir("prefabs", (err, res) => {
                    if (!err) {
                        GameMgr.instance.cardPrefabs = res
                        this.initData()
                    }
                })
                
            }
        })
    }

    initData() {
        GameMgr.instance.loadGameByLevel()
    }

    start() {

    }

    // update (dt) {}
}
